package com.miaoxie.web.controller;

import com.miaoxie.domain.UserEntity;
import com.miaoxie.service.RedisCache;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: miaoxie
 * Date: 2018-01-23
 * Time: 上午10:50
 */
@RestController
@RequestMapping(value = "/testController")
public class TestController extends ResponseMessageController{
    @Value(value = "${miaoxie.string.random}")
    private String randomStringValue;
    @Value(value = "${miaoxie.doc}")
    private String testDoc;
    @Autowired
    private RedisCache redis;

    @ApiOperation(value="test-index", notes="")
    @RequestMapping(value = "/index")
    public String index(){
        return "hello word111";
    }

    @ApiOperation(value="test-getParm", notes="")
    @RequestMapping(value = "/get")
    public Map<String,String> get(@RequestParam String name){
        Map<String,String> o = new HashMap<>();
        o.put("aaa",name);
        return o;
    }
    @ApiOperation(value="test-getUser", notes="")
    @ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
    @RequestMapping(value = "/getUser/{name}/{age}/{sex}")
    public UserEntity getUser(@PathVariable String name,
                                      @PathVariable Integer age,
                                      @PathVariable String sex){
        UserEntity userEntity = new UserEntity(name,age,sex);
        return userEntity;
    }
    @ApiOperation(value="test-testRandomValue", notes="")
    @RequestMapping(value = "/testRandomValue")
    public Map<String,Object> testRandomValue(){
        this.getMap().put("randomString",randomStringValue);
        this.getMap().put("testDoc",testDoc);
        return returnSuccess();
    }
    @ApiOperation(value="test-testredis", notes="")
    @RequestMapping(value = "/testredis")
    public Map<String,Object> testredis(){
     redis.get("miaoxie");

        return returnSuccess();
    }
}
